using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.LogServices.Dtos;
using IM.Easy.LogServices.IServices;
using IM.Easy.Entity.Log;
using IM.Easy.Core.Attributes;

namespace IM.Easy.Api.Controllers.Log
{
    /// <summary>
    /// SessionLogController 控制器
    /// </summary>
    [Route("log/session")]
    public class SessionLogController : ControllerBase
    {
        private readonly ISessionLogService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public SessionLogController(ISessionLogService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取所有SessionLog对象
        /// </summary>
        /// <returns>返回SessionLog列表</returns>
        [HttpGet]
        [Api(Name = "登录日志列表", Perm = "signin:list")]
        public PageResponse<SessionLog> GetList([FromQuery] SessionLogQueryDto query)
        {
            return _service.GetPageList(query);
        }

        /// <summary>
        /// 根据ID获取SessionLog对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns>返回指定的SessionLog对象</returns>
        [HttpGet("{id}")]
        [Api(Name = "登录日志详情", Perm = "signin:info")]
        public SessionLog GetById(Guid id)
        {
            var result = _service.GetById(id);
            return result ?? throw new KeyNotFoundException($"未找到ID为 {id} 的SessionLog对象。");
        }


        /// <summary>
        /// 更新现有的SessionLog对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <param name="entity">更新后的SessionLog对象</param>
        [HttpPut]
        public void Update([FromBody] SessionLog entity)
        {
            _service.Update(entity);
        }

        /// <summary>
        /// 删除SessionLog对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [HttpDelete]
        [Api(Name = "删除登录日志", Perm = "signin:del")]
        public void Delete([FromBody] Guid[] ids)
        {
            _service.Delete(ids);
        }
    }
}
